//
// Copyright (C) 2011 - 2013  Steve Channell steve.channell@cepheis.com
//
// This file is part of Cephei.QL, an open-source library wrapper 
// arround QuantLib http://quantlib.org/
//
// Cephei.QL is open source software: you can redistribute it and/or modify it
// under the terms of the license.  You should have received a
// copy of the license along with this program; if not, please email
// <support@cepheis.com>. The license is also available online at
// <http://cepheis.com/license.htm>.
//
// This program is distributed in the hope that it will be useful, but WITHOUT
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
// FOR A PARTICULAR PURPOSE.  See the license for more details.
//
// Version 2.2 with QuantLib 1.2.1
//#include "stdafx.h"
#include "GaussLaguerrePolynomial.h"
using namespace Cephei::QL::Math::Integrals;
#include <gen/QL/Math/Integrals/GaussianOrthogonalPolynomial.h>
#undef HANDLE
#undef ABSTRACT
#undef STRUCT
Cephei::QL::Math::Integrals::CGaussLaguerrePolynomial::CGaussLaguerrePolynomial (Microsoft::FSharp::Core::FSharpOption<Double>^ s) : CGaussianOrthogonalPolynomial(CGaussLaguerrePolynomial::typeid)
{
    try
    {
#ifdef HANDLE
        _phGaussLaguerrePolynomial = NULL;
#endif
        QuantLib::Real _s = 
            (Microsoft::FSharp::Core::FSharpOption<Double>::IsSome::get (s) ? (QuantLib::Real)ValueHelper::Convert (s->Value) : 0.0); //4
        _ppGaussLaguerrePolynomial = new boost::shared_ptr<QuantLib::GaussLaguerrePolynomial> (new QuantLib::GaussLaguerrePolynomial ( _s ));
        SetGaussianOrthogonalPolynomial (boost::dynamic_pointer_cast<QuantLib::GaussianOrthogonalPolynomial> (*_ppGaussLaguerrePolynomial));
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown std::exception"));
	}
    finally
    {
    }
}
Cephei::QL::Math::Integrals::CGaussLaguerrePolynomial::CGaussLaguerrePolynomial (boost::shared_ptr<QuantLib::GaussLaguerrePolynomial>& childNative, Object^ owner) : CGaussianOrthogonalPolynomial(CGaussLaguerrePolynomial::typeid)
{
#ifdef HANDLE
	_phGaussLaguerrePolynomial = NULL;
#endif
	_ppGaussLaguerrePolynomial = &childNative;
    _ppGaussianOrthogonalPolynomial = new boost::shared_ptr<QuantLib::GaussianOrthogonalPolynomial> (boost::dynamic_pointer_cast<QuantLib::GaussianOrthogonalPolynomial> (*_ppGaussLaguerrePolynomial));
}
Cephei::QL::Math::Integrals::CGaussLaguerrePolynomial::CGaussLaguerrePolynomial (QuantLib::GaussLaguerrePolynomial& childNative, Object^ owner) : CGaussianOrthogonalPolynomial(CGaussLaguerrePolynomial::typeid)
{
#ifdef HANDLE
	_phGaussLaguerrePolynomial = NULL;
#endif
	_ppGaussLaguerrePolynomial = new boost::shared_ptr<QuantLib::GaussLaguerrePolynomial> (&childNative);
    _ppGaussianOrthogonalPolynomial = new boost::shared_ptr<QuantLib::GaussianOrthogonalPolynomial> (boost::dynamic_pointer_cast<QuantLib::GaussianOrthogonalPolynomial> (*_ppGaussLaguerrePolynomial));
    _GaussLaguerrePolynomialOwner = owner;
    _GaussianOrthogonalPolynomialOwner = owner;
}

Cephei::QL::Math::Integrals::CGaussLaguerrePolynomial::CGaussLaguerrePolynomial (CGaussLaguerrePolynomial^ copy) : CGaussianOrthogonalPolynomial(CGaussLaguerrePolynomial::typeid)
{
#ifdef HANDLE
	_phGaussLaguerrePolynomial = NULL;
#endif
	if (copy->HasNative() != NULL)
    {
		_ppGaussLaguerrePolynomial = new boost::shared_ptr<QuantLib::GaussLaguerrePolynomial> (copy->GetShared());
        _ppGaussianOrthogonalPolynomial = new boost::shared_ptr<QuantLib::GaussianOrthogonalPolynomial> (boost::dynamic_pointer_cast<QuantLib::GaussianOrthogonalPolynomial> (*_ppGaussLaguerrePolynomial));
    }
}
Cephei::QL::Math::Integrals::CGaussLaguerrePolynomial::CGaussLaguerrePolynomial (PLATFORM::Type^ t) : CGaussianOrthogonalPolynomial(CGaussLaguerrePolynomial::typeid)
{
#ifdef HANDLE
	_phGaussLaguerrePolynomial = NULL;
#endif
	if (!t->IsSubclassOf(CGaussLaguerrePolynomial::typeid))
		throw REFNEW Exception ("Invalid base-case init");
}
#ifdef HANDLE
Cephei::QL::Math::Integrals::CGaussLaguerrePolynomial::CGaussLaguerrePolynomial (QuantLib::Handle<QuantLib::GaussLaguerrePolynomial>& childNative, Object^ owner)  : CGaussianOrthogonalPolynomial(CGaussLaguerrePolynomial::typeid)
{
	_phGaussLaguerrePolynomial = &childNative;
	_ppGaussLaguerrePolynomial = &static_cast<boost::shared_ptr<QuantLib::GaussLaguerrePolynomial>>(childNative.currentLink());
    _ppGaussianOrthogonalPolynomial = new boost::shared_ptr<QuantLib::GaussianOrthogonalPolynomial> (boost::dynamic_pointer_cast<QuantLib::GaussianOrthogonalPolynomial> (*_ppGaussLaguerrePolynomial));
    _GaussLaguerrePolynomialOwner = owner;
}
Cephei::QL::Math::Integrals::CGaussLaguerrePolynomial::CGaussLaguerrePolynomial (QuantLib::Handle<QuantLib::GaussLaguerrePolynomial> childNative)  : CGaussianOrthogonalPolynomial(CGaussLaguerrePolynomial::typeid)
{
	_phGaussLaguerrePolynomial = &childNative;
	_ppGaussLaguerrePolynomial = &static_cast<boost::shared_ptr<QuantLib::GaussLaguerrePolynomial>>(childNative.currentLink());
    _ppGaussianOrthogonalPolynomial = new boost::shared_ptr<QuantLib::GaussianOrthogonalPolynomial> (boost::dynamic_pointer_cast<QuantLib::GaussianOrthogonalPolynomial> (*_ppGaussLaguerrePolynomial));
}
#endif
#ifdef STRUCT
Cephei::QL::Math::Integrals::CGaussLaguerrePolynomial::CGaussLaguerrePolynomial (QuantLib::GaussLaguerrePolynomial childNative)  : CGaussianOrthogonalPolynomial(CGaussLaguerrePolynomial::typeid)
{
#ifdef HANDLE
	_phGaussLaguerrePolynomial = NULL;
#endif
	_ppGaussLaguerrePolynomial = new boost::shared_ptr<QuantLib::GaussLaguerrePolynomial> (new QuantLib::GaussLaguerrePolynomial (childNative));
    _ppGaussianOrthogonalPolynomial = new boost::shared_ptr<QuantLib::GaussianOrthogonalPolynomial> (boost::dynamic_pointer_cast<QuantLib::GaussianOrthogonalPolynomial> (*_ppGaussLaguerrePolynomial));
}
#endif

Cephei::QL::Math::Integrals::CGaussLaguerrePolynomial::~CGaussLaguerrePolynomial ()
{
    if (_ppGaussLaguerrePolynomial != NULL)
    {
	    delete _ppGaussLaguerrePolynomial;
        _ppGaussLaguerrePolynomial = NULL;
    }
}
Cephei::QL::Math::Integrals::CGaussLaguerrePolynomial::!CGaussLaguerrePolynomial ()
{
    if (_ppGaussLaguerrePolynomial != NULL)
    {
	    delete _ppGaussLaguerrePolynomial;
    }
}
QuantLib::GaussLaguerrePolynomial& Cephei::QL::Math::Integrals::CGaussLaguerrePolynomial::GetReference ()
{
    if (_ppGaussLaguerrePolynomial == NULL) throw REFNEW NativeNullException ();
	return **_ppGaussLaguerrePolynomial;
}
boost::shared_ptr<QuantLib::GaussLaguerrePolynomial>& Cephei::QL::Math::Integrals::CGaussLaguerrePolynomial::GetShared ()
{
    if (_ppGaussLaguerrePolynomial == NULL) throw REFNEW NativeNullException ();
	return *_ppGaussLaguerrePolynomial;
}
QuantLib::GaussLaguerrePolynomial* Cephei::QL::Math::Integrals::CGaussLaguerrePolynomial::GetPointer ()
{
    if (_ppGaussLaguerrePolynomial == NULL) throw REFNEW NativeNullException ();
	return &**_ppGaussLaguerrePolynomial;
}
#ifdef HANDLE
QuantLib::Handle<QuantLib::GaussLaguerrePolynomial>& Cephei::QL::Math::Integrals::CGaussLaguerrePolynomial::GetHandle ()
{
	if (_phGaussLaguerrePolynomial == NULL)
	{
		_phGaussLaguerrePolynomial = new Handle<QuantLib::GaussLaguerrePolynomial> (*_ppGaussLaguerrePolynomial);
	}
	return *_phGaussLaguerrePolynomial;
}
#endif
bool Cephei::QL::Math::Integrals::CGaussLaguerrePolynomial::HasNative () 
{
	return (_ppGaussLaguerrePolynomial != NULL);
}

Double Cephei::QL::Math::Integrals::CGaussLaguerrePolynomial::Alpha (UInt64 i)
{
    try
    {
        QuantLib::Size _i = (QuantLib::Size)ValueHelper::Convert (i); //a
    	QuantLib::Real _rv = (QuantLib::Real)(*_ppGaussLaguerrePolynomial)->alpha ( _i );   
        Double _nrv = (Double)ValueHelper::Convert (_rv); //c
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown std::exception"));
	}
    finally
    {
    }
}
Double Cephei::QL::Math::Integrals::CGaussLaguerrePolynomial::Beta (UInt64 i)
{
    try
    {
        QuantLib::Size _i = (QuantLib::Size)ValueHelper::Convert (i); //a
    	QuantLib::Real _rv = (QuantLib::Real)(*_ppGaussLaguerrePolynomial)->beta ( _i );   
        Double _nrv = (Double)ValueHelper::Convert (_rv); //c
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown std::exception"));
	}
    finally
    {
    }
}
Double Cephei::QL::Math::Integrals::CGaussLaguerrePolynomial::Mu_0::get ()
{
    try
    {
    	QuantLib::Real _rv = (QuantLib::Real)(*_ppGaussLaguerrePolynomial)->mu_0 ( );   
        Double _nrv = (Double)ValueHelper::Convert (_rv); //c
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown std::exception"));
	}
    finally
    {
    }
}
Double Cephei::QL::Math::Integrals::CGaussLaguerrePolynomial::W (Double x)
{
    try
    {
        QuantLib::Real _x = (QuantLib::Real)ValueHelper::Convert (x); //a
    	QuantLib::Real _rv = (QuantLib::Real)(*_ppGaussLaguerrePolynomial)->w ( _x );   
        Double _nrv = (Double)ValueHelper::Convert (_rv); //c
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown std::exception"));
	}
    finally
    {
    }
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Factory class

Cephei::QL::Math::Integrals::IGaussLaguerrePolynomial^ Cephei::QL::Math::Integrals::CGaussLaguerrePolynomial_Factory::Create (Microsoft::FSharp::Core::FSharpOption<Double>^ s)
{
    return REFNEW CGaussLaguerrePolynomial ( s);
}
